package com.ioftv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ioftv.entity.QcStatistics;
import com.ioftv.mapper.QcStatisticsMapper;
import com.ioftv.service.QcStatisticsService;
import com.ioftv.service.base.BaseService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * 质检统计Service实现类
 */
@Service
public class QcStatisticsServiceImpl extends BaseService<QcStatisticsMapper, QcStatistics> implements QcStatisticsService {

    @Override
    public List<QcStatistics> getByStatDate(LocalDate statDate) {
        LambdaQueryWrapper<QcStatistics> queryWrapper = createUserQueryWrapper();
        queryWrapper.eq(QcStatistics::getStatDate, statDate);
        queryWrapper.orderByDesc(QcStatistics::getCreateTime);
        return this.list(queryWrapper);
    }
    
    @Override
    public List<QcStatistics> getByStatDateAndUserId(LocalDate statDate, Long userId) {
        LambdaQueryWrapper<QcStatistics> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(QcStatistics::getUserId, userId);
        queryWrapper.eq(QcStatistics::getStatDate, statDate);
        queryWrapper.orderByDesc(QcStatistics::getCreateTime);
        return this.list(queryWrapper);
    }

    @Override
    protected void addUserCondition(LambdaQueryWrapper<QcStatistics> queryWrapper) {
        queryWrapper.eq(QcStatistics::getUserId, getCurrentUserId());
    }

    @Override
    protected void setEntityUserId(QcStatistics entity) {
        if (entity.getUserId() == null) {
            entity.setUserId(getCurrentUserId());
        }
    }
}